package cn.ptu.pmaa.mapper;

import cn.ptu.pmaa.entities.Appintment;
import cn.ptu.pmaa.entities.ClassRoom;
import cn.ptu.pmaa.entities.Teacher;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TeacherMapper {

//    @Select("SELECT jsid,jsld,jsfh,jszws\n" +
//            "FROM classroom\n" +
//            "WHERE jsid NOT IN (SELECT yydjsid\n" +
//            "FROM `appintment` \n" +
//            "WHERE yyrq = #{date} \n" +
//            "AND (yykssj BETWEEN #{fromtime} AND #{totime} ) \n" +
//            "AND (yyjssj BETWEEN #{fromtime} AND #{totime} )\n" +
//            "GROUP BY yydjsid)")
    @Select("SELECT jsid,jsld,jsfh,jszws\n" +
            "FROM classroom\n" +
            "WHERE sfqy=1 AND sfkfgxs=0\n" +
            "AND jsid NOT IN (SELECT yydjsid\n" +
            "FROM `appintment` \n" +
            "WHERE (yyrq = #{date} \n" +
            "\t\t\t\t\tAND (\n" +
            "\t\t\t\t\t\t\t(yykssj BETWEEN #{fromtime} AND #{totime} ) OR (yyjssj BETWEEN #{fromtime} AND #{totime} )\n" +
            "\t\t\t\t\t)\n" +
            "\t\t\t)\n" +
            "GROUP BY yydjsid)")
    public List<ClassRoom> getSiteByTime(@Param("fromtime") String fromtime, @Param("totime") String totime, @Param("date") String date);


    @Insert("INSERT INTO appintment(yydjsid,yyrq,yykssj,yyjssj,yyrid,yyrjs) " +
            "VALUES(#{yydjsid},#{yyrq},#{yykssj},#{yyjssj},#{yyrid},#{yyrjs})")
    public int insertAppintment(Appintment appintment);

    @Select("SELECT * FROM appintment WHERE yyrid=#{yyrid}")
    public List<Appintment> getAppintment(@Param("yyrid") String id);

    @Select("SELECT yyrid FROM appintment WHERE yyid=#{id}")
    public String getUserIdByYyid(@Param("id") String id);

    @Update("UPDATE appintment SET state = 0 WHERE yyid=#{id}")
    public int setAppiState(@Param("id") String id);

    @Update("UPDATE appintment SET yyjssj=#{time} WHERE yyid=#{id}")
    public int setYyjssj(@Param("id") String id,@Param("time") String time);

    @Update("UPDATE teacher SET teachername=#{teacherName},teachersex=#{teacherSex},teachertel=#{teacherTel},teacheremail=#{teacherEmail}" +
            " WHERE teacherid=#{teacherId}")
    public int setStudentInfo(Teacher teacher);

}
